package org.action;

import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.model.Kcb;
import org.model.Xsb;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sun.java.util.jar.pack.Package$File;

public class XsAction extends ActionSupport{
	XsDao xsDao;
	private Xsb xs;
	private Kcb kcb;
	private File zpFile;
	private Zyb zyb;
	public File getZpFile(){
		return zpFile;
	}
	public void setZpFile(File zpFile){
		this.zpFile=zpFile;
	}
	public Kcb getKcb(){
		return kcb;
	}
	public void setKcb(Kcb kcb){
		this.kcb=kcb;
	}
	public Zyb getZyb(){
		return zyb;
	}
	public void setZyb(Zyb zyb){
		this.zyb=zyb;
	}
	public Xsb getXs(){
		return xs;
	}
	public void setXs(Xsb xs){
		this.xs=xs;
	}
	public String execute()throws Exception{
		Map session=(Map)ActionContext.getContext().getSession();
		Dlb user=(Dlb)session.get("user");
		xsDao=new XsDaoImp();
		Xsb xs=xsDao.getOneXs(user.getXh());
		Map request=(Map)ActionContext.getContext().get("request");
		request.put("xs", xs);
		return SUCCESS;
	}
	public String getImage()throws Exception{
		xsDao=new XsDaoImp();
		byte[]zp=xsDao.getOneXs(xs.getXh()).getZp();
		HttpServletResponse response=ServletActionContext.getResponse();
		response.setContentType("image/jpeg");
		ServletOutputStream os=response.getOutputStream();
		if(zp!=null&&zp.length>0){
			for(int i=0;i<zp.length;i++){
				os.write(zp[i]);
			}
		}
		return NONE;
	}
}
